

/**
 * @(#)Products.java
 *
 *
 * @author
 * @version 1.00 2009/8/20
 */
import java.io.*;
import java.util.ArrayList;

public class Product implements Ingredients {

	private String nameProduct;
	private int quantity;
	private int numRawMaterial;
	private ArrayList<Ingredients> rawMeterials;// = new ArrayList<Ingredients>();
        private ArrayList numRMNeeded ;//= new ArrayList();    // store num each RM needed for each product
	private int invOnHand;
	//private int amount;	// number of bottles used for each product

    public Product() {
        nameProduct = "";
        quantity = 0;
        numRawMaterial = 0;
        rawMeterials = new ArrayList<Ingredients>();
        numRMNeeded = new ArrayList();
        invOnHand = 0;
        //amount = 0;

    }

    public Product(String name, int num) {
    	nameProduct = name;
    	numRawMaterial = num;
        rawMeterials = new ArrayList<Ingredients>();
        numRMNeeded = new ArrayList(); 
    }

    /* set num of raw material */
    public void setNumRawMaterial(int num) {
        numRawMaterial = num;
    }

    /* get num of raw material*/
    public int getNumRawMaterial() {
    	return numRawMaterial;
    }
    
    /* set quantity */
    public void setQuantity(int quan) {
    	quantity = quan;
    }

    /* Get name of a product. */
    public String getNameProduct() {
    	return nameProduct;
    }

    public void setNameProduct(String name) {
        nameProduct = name;
    }

    /* get quantity of a product. */
    public int getQuantity() {
    	return quantity;
    }

    /* set number of each inventory needed for a product,
     * and set inventory needed for a product */
    /*public void setRawMeterials(Ingredients inv, int num) {
    	rawMeterials.add(inv);
        numRMNeeded.add(num);
    }*/

    public void setRawMeterials(ArrayList<Ingredients> inv, ArrayList num) {
        rawMeterials = inv;
        numRMNeeded = num;
    }

    /* Calculate raw materials left after using to produce particular number of product */
    public void canculateInv() {
    	for (int i=0; i<rawMeterials.size(); ++i) {
    		int amount = quantity*(Integer) numRMNeeded.get(i);
    		rawMeterials.get(i).countInv(amount);
    	}
    }

    public ArrayList<Ingredients> getRawMeterials() {
        return rawMeterials;
    }

/*    public ArrayList checkInvenOnHand() {
        ArrayList temp = new ArrayList();
        for (int i = 0; i < rawMeterials.size(); ++i) {
            int num = rawMeterials.get(i).getInvenOnHand();
            if (num < 0) {
                temp.add(i);
                rawMeterials.get(i).setInvOnhand(0-num);
            }
        }
        return temp;
    }*/

    /* print a list of inventories needed for each vanilla */
    public ArrayList getNumRMNeeded() {
    	return numRMNeeded;
    }

    /*public void setNumRMNeeded(ArrayList num) {
        numRMNeeded = num;
    }*/
    
    /* set number of raw material needed to produce a product */
    /*public void setAmount(int num){
    	amount = num;
    }*/

    /* order inventory */
    public void setInvOnHand(int num) {
        this.setQuantity(num);
        this.canculateInv(); // Calculate raw materials left
        for (int i = 0; i < rawMeterials.size(); ++i) {
            SupplyChainManagement.checkOrder((Ingredients) rawMeterials.get(i));
            System.out.println(rawMeterials.get(i).getNameProduct() + " " + rawMeterials.get(i).getInvOnHand());
        }
    }

    /* deduct inventory on hand after using */
    public void countInv(int used) {
    	invOnHand = invOnHand - used;
    }

    /* get current avaible bottles */
    public int getInvOnHand() {
    	return invOnHand;
    }

}